
<%@ page import="com.capgemini.rdlgae.domain.Commande" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'commande.label', default: 'Commande')}" />
        <title><g:message code="default.edit.label" args="[entityName]" /></title>
        <g:javascript library="prototype" />
    </head>
    <body>
        <div class="nav">
            
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
            <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
        </div>
        <div class="body">
            <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${commandeInstance}">
            <div class="errors">
                <g:renderErrors bean="${commandeInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form method="post" >
                <g:hiddenField name="id" value="${commandeInstance?.id}" />
                <g:hiddenField name="version" value="${commandeInstance?.version}" />
                <div class="dialog">
                    <table>
                        <tbody>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="dateCommande"><g:message code="commande.dateCommande.label" default="Date Commande" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: commandeInstance, field: 'dateCommande', 'errors')}">
                                    <g:datePicker name="dateCommande" precision="day" value="${commandeInstance?.dateCommande}"  />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="entree"><g:message code="commande.entree.label" default="Entree" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: commandeInstance, field: 'entree', 'errors')}">
                                    <g:select name="entree.id" from="${com.capgemini.rdlgae.domain.Entree.list()}" optionKey="id" value="${commandeInstance?.entree?.id}" 
                                    noSelection="['null':'']"
                                    onchange="updatePrix()" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="plat"><g:message code="commande.plat.label" default="Plat" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: commandeInstance, field: 'plat', 'errors')}">
                                    <g:select name="plat.id" from="${com.capgemini.rdlgae.domain.Plat.list()}" optionKey="id" value="${commandeInstance?.plat?.id}"  
                                    onchange="updatePrix()"/>
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="dessert"><g:message code="commande.dessert.label" default="Dessert" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: commandeInstance, field: 'dessert', 'errors')}">
                                    <g:select name="dessert.id" from="${com.capgemini.rdlgae.domain.Dessert.list()}" optionKey="id" value="${commandeInstance?.dessert?.id}"
                                    noSelection="['null':'']"
                                    onchange="updatePrix()" />
                                </td>
                            </tr>
                        		<tr class="prop">
				<td valign="top" class="name"><label for="commentaire"><g:message
					code="commande.commentaire.label" default="Commentaire" /></label></td>
				<td valign="top"
					class="value ${hasErrors(bean: commandeInstance, field: 'commentaire', 'errors')}">
				<g:textField name="commentaire" id="commentaire" value="${commandeInstance?.commentaire}"/>
					
				</td>
			</tr>
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="utilisateur"><g:message code="commande.utilisateur.label" default="Utilisateur" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: commandeInstance, field: 'utilisateur', 'errors')}">
                                    <g:select name="utilisateur.id" from="${com.capgemini.rdlgae.domain.Utilisateur.list()}" optionKey="id" value="${commandeInstance?.utilisateur?.id}"  />
                                </td>
                            </tr>
                        
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="total"><g:message code="commande.total.label" default="Total" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: commandeInstance, field: 'total', 'errors')}">
                                    <div name="total_commande" id="total_commande"> </div>
                                </td>
                            </tr>
                        
                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                    <span class="button"><g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" /></span>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                </div>
                <g:javascript>
	function updatePrix(){	
		${remoteFunction(action:'calculerTotal', params:'\'idEntree=\'+ document.getElementById(\'entree.id\').value +\'&idPlat=\'+ document.getElementById(\'plat.id\').value+\'&idDessert=\'+ document.getElementById(\'dessert.id\').value', update:'total_commande', onFailure:'alert(\'erreur\')')}
	}
	updatePrix();
	</g:javascript>
            </g:form>
        </div>
    </body>
</html>
